;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Enterprise.EnterpriseInfo", [])
        .controller("EnterpriseInfoCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, UserContextService) {
            $scope.submitted = false;
            $scope.detailInfo = {};

            function getUserInfo() {
                var service = "device";
                var reqUrl = "/company/selfCompanyInfo";
                ybHttp.Get(service, reqUrl).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.detailInfo = resp.value;
                });
            }

            function saveData(service, reqUrl, param) {
                return ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    return resp.value;
                });
            }

            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }
                var service = "device";
                var reqUrl = "/company/updateInfo";
                var param = {};
                param.shortName = $scope.detailInfo.shortName;
                param.address = $scope.detailInfo.address;
                param.contact = $scope.detailInfo.contact;
                param.contactTel = $scope.detailInfo.contactTel;
                param.zip = $scope.detailInfo.zip;
                param.fax = $scope.detailInfo.fax;
                saveData(service, reqUrl, param).then(function (data) {
                    ybWidget.ShowToaster('success', '操作成功');
                    getUserInfo();
                    $scope.submitted = false;
                });
            };

            $scope.resetData = function () {
                getUserInfo();
            };

            (function () {
                getUserInfo();
            })();
        }])
    ;
})(window, window.angular);